<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script>
        $(function () {
            // 添加/编辑按钮
            $(".inputBtn").click(function () {
                $("#inputModal input").val('');
                var json = $(this).data('json');
                if (json){
                    $("#inputModal input[name=id]").val(json.id);
                    $("#inputModal input[name=name]").val(json.name);
                    $("#inputModal input[name=sequence]").val(json.sequence);
                    $("#inputModal select[name=state]").val(json.state+""); // 变成字符串在回显
                    $("#fromStrategySelect").val(json.strategyId);
                }else {
                    // 把查询到下拉框的值设置到表单下拉框
                    $("#fromStrategySelect").val($("#strategySelect").val());
                }
                $("#inputModal").modal('show');
            })

            // 提交按钮
            $(".submitBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    handleMessage(data);
                })
            })
        })
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign currentMenu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略目录管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>所属攻略:</label>
                    <select class="form-control" name="strategyId" id="strategySelect" >
                        <option value="-1">查询全部</option>
                    <#list strategies as s>
                        <option value="${s.id}">${s.title}</option>
                    </#list>
                    </select>
                    <script>
                        $("#strategySelect").val(${(qo.strategyId)!});
                    </script>
                    </select>

                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

            <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.name}</td>
                        <td>${entity.strategy.title}</td>
                        <td>${entity.sequence}</td>
                        <td>${entity.state?string("启用","禁用")}</td>
                        <td>
                            <a class="btn btn-warning btn-sm inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm">

                    <input type="hidden" name="id">
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="strategy.id" id="fromStrategySelect">
                                <#list strategies as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state" >
                                <option value="true">启用</option>
                                <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 戳我关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 朕要保存
                </button>
            </div>
        </div>
    </div>
</div>
</body>
</html>